package com.xzan.medusa.core.ao.impl;

import com.xzan.medusa.common.entity.AppBizResult;
import com.xzan.medusa.common.form.stock.StockStrategyForm;
import com.xzan.medusa.common.service.IRabbitMqService;
import com.xzan.medusa.common.util.BeanCopierUtil;
import com.xzan.medusa.core.ao.StockStrategyAO;
import com.xzan.medusa.core.manager.CcCarManager;
import com.xzan.medusa.core.manager.StockStrategyManager;
import com.xzan.medusa.dal.model.StockStrategyDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class StockStrategyAOImpl implements StockStrategyAO {
    @Autowired
    private StockStrategyManager stockStrategyManager;
    @Autowired
    private CcCarManager ccCarManager;
    @Autowired
    private IRabbitMqService rabbitMqService;
    @Override
    public AppBizResult<Boolean> addStockStrategy(StockStrategyForm stockStrategyForm) {
        if (Objects.isNull(stockStrategyForm)){
            return AppBizResult.create(Boolean.FALSE);
        }
        if (Objects.isNull(stockStrategyForm.getBuyAmount())){
            return AppBizResult.bizError("content can not be null");
        }
        StockStrategyDO stockStrategyDO= BeanCopierUtil.convert(stockStrategyForm,StockStrategyDO.class);
        stockStrategyDO.setStatus(1);
        rabbitMqService.sendMessage("event_queue",stockStrategyDO);
        return AppBizResult.success(Boolean.TRUE);
    }
}
